// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({env: 'test-qch4n'})
const db = cloud.database({env: 'test-qch4n'})

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  try {
    const res = await db.collection('admin').where({
      uid: wxContext.OPENID
    }).get()
    const permission = res.data.length > 0
    console.log(res)
    return {
      event,
      openid: wxContext.OPENID,
      appid: wxContext.APPID,
      unionid: wxContext.UNIONID,
      permission
    }
  } catch (error) {
    console.log(error)
  }
}